<?php
//Manga auto complete home search ----------
if(isset($_GET['manga_search_home'])){
	
		$val=$_GET['q'];
		$find=false;
		
		$db=new db;
		$db->connect();
		
		//Tim ten manga
		$sql="select id,name,alias from anime  WHERE alias  like '%".khongdau($val)."%' and adult=0";
		$db->query($sql);
			
		if($db->num_rows()>0){
			$find=true;	
			$dt=$db->fetchAll();	
			foreach($dt as $row){				
					$answer[] = array("id"=>mangaf1_url_manga($row['id'],$row['alias']),"text"=>$row['name']);		
			}
		}
		//Group dich
		$sql="select id,name,alias from anime_fansub WHERE alias  like '%".khongdau($val)."%' ";
		$db->query($sql);
			
		if($db->num_rows()>0){
			$find=true;	
			$dt=$db->fetchAll();	
			foreach($dt as $row){				
					$answer[] = array("id"=>mangaf1_url_manga_nguon($row['alias']),"text"=>"[GROUP] ".$row['name']);		
			}
		}
		
		
		
		
		if($find==false){ 
		$answer[] = array("id"=>"0","text"=>"Không Tìm Thấy Kết quả");
		}
		
		$db->close();
		
		echo json_encode($answer);
		exit();


}
